/** Part of Zombie Navigator
	Copyright © 2016  Zombie Navigator Developers
	
	@file
	@module
	@license AGPL-3.0+
	
*/ 'use strict';


/* Addon SDK dependencies */
const _sdkSystem = require('sdk/system');


/* Used modules */
const _pOptions = require('./options');

/* Private properties */

/** @private */
const ENV_PREFIX = 'ZOMBIE_NAVIGATOR_';


/* Internal APIs */

/*
	Only readonly access is supported (on purpose)
*/

/**
	@public
	@method
	@param {string} name
	@returns {string}
*/
const toEnvName = name => (ENV_PREFIX + (name + '').toUpperCase());

/**
	@public
	@method
	@param {string} name
	@returns {string}
*/
const get = name => {
	const {envEnabled} = _pOptions;
	if (!envEnabled()) return '';
	
	const sdkSystem = _sdkSystem;
	return (sdkSystem.env[toEnvName(name)] || '') + ''; // avoid literal 'undefined' (string)
};

/**
	@public
	@method
	@param {string} name
	@returns {boolean}
*/
const has = name => {
	const {envEnabled} = _pOptions;
	if (!envEnabled()) return false;
	
	const sdkSystem = _sdkSystem;
	return !!(toEnvName(name) in sdkSystem.env);
};


/* Exports */
exports.toEnvName = toEnvName;
exports.get = get;
exports.has = has;


// vim: ts=4 noet ai

